<?php

/**
 * Demózható adatok.
 *
 * @author Zsolt Lengyel
 *
 */
class m130213_225900_demo extends CDbMigration
{
    public function up()
    {

        // user generation

            $this->createTable('user', array(
                    'id' => 'pk',
                    'username' => "VARCHAR(255) NOT NULL",
                    'fullname'=> "VARCHAR(255) NOT NULL",
                    'email' => "VARCHAR(255) NOT NULL",
                    'password'=> "VARCHAR(255) NOT NULL",
            ));
            $this->createIndex('unique_username', 'user', 'username', true);

            Yii::import('application.models.*');

            // add admin user
            $admin = new User();
            $admin->username = 'admin';
            $admin->password = '3G6UkF9yL4';
            $admin->email = 'admin@triola.hu';
            $admin->fullname = 'Adminisztrátor';

            $admin->save();

            // Gallery
            $this->createTable('gallery', array(
                  'id'=> 'pk',
                  'versions_data'=> 'TEXT NOT NULL' ,
                  'name'=> 'TINYINT(1) NOT NULL DEFAULT 1',
                  'description'=> 'TINYINT(1) NOT NULL DEFAULT 1' ,
                  ));

            $this->createTable('gallery_photo', array(
                  'id'=> 'pk' ,
                  'gallery_id'=> 'INT NOT NULL',
                  'rank' =>'INT NOT NULL DEFAULT 0' ,
                  'name' => 'VARCHAR(512) NOT NULL DEFAULT \'\'',
                  'description' => 'TEXT NULL',
                  'file_name' => 'VARCHAR(128) NOT NULL DEFAULT \'\'',
                  ));
            $this->addForeignKey('gallery_fk','gallery_photo', 'gallery_id', 'gallery', 'id');

            // Page schema

            $this->createTable('page', array(
                    'id' => 'pk',
                    'title' => "VARCHAR(255) NOT NULL",
                    'description'=> "TEXT NOT NULL",
                    'content' => "text DEFAULT NULL",
                    'controller'=> "VARCHAR(255) DEFAULT NULL",
                    'parent_id'=> "int(11) DEFAULT NULL",
                    'active'=>'tinyint(1) not null default \'1\''
            ));
            $this->createIndex('unique_title', 'page', 'title', true);
            $this->addForeignKey('parent_fk','page', 'parent_id', 'page', 'id');

    }

    public function down()
    {

        $this->dropTable('user');
        $this->dropTable('page');


    }

}